define(["jquery","getCookie","setCookie"],function($,getCookie,setCookie){
	return function userLogin(){
		//console.log($("#loginTo"));
		
		//取出用户输入的信息
		let user_id = document.getElementById("userPhoneNum");
		let user_pwd = document.getElementById("userPwd");
		let autoLogin = document.getElementById("autoLogin");
		let _status = [false,false]; //登陆状态
		
		//点击登录做判断
		$("#loginTo").click(function(){
			if(document.cookie!= ""){ //是否存在cookie
				//取出cookie的值
				//console.log(getCookie("userId"));
				let ids = getCookie("userId")[1].split("%");
				let pwds = getCookie("userPwd")[1].split(",");
				
				//匹配id值
				for(let i = 0;i<ids.length;i++){
					if(ids[i] == user_id.value){ //如果匹配到id
						_status[0] =true;
						break;
					}
				}
				//匹配密码
				for(let i = 0;i<pwds.length;i++){
					if(pwds[i] == user_pwd.value){ //如果匹配到密码
						_status[1] =true;
						break;
					}
				}
				console.log(_status);
			}
				
			
			
			//判断是否为空
			if(user_id.value != ""){ //用户名
				if(user_pwd.value != ""){ //密码
					//用户名和密码都不为空时
					if(_status[0]){ //用户是否正确
						if(_status[1]){ //密码是否正确
							
							//判断是否自动登录
							console.log(autoLogin.checked)
							if(autoLogin.checked){
								//alert("自动登陆");
					 			setCookie("username",user_id.value,10);
					 			setCookie("userpass",user_pwd.value,10);
							}
							
							window.location.href="../index/index.html";  //全部正确跳转
						}else{
							alert("密码错误！");
							user_id.style.borderColor = "red";
						}
					}else{
						alert("用户名不存在！");
						user_id.style.borderColor = "red";
					}
				}else{
					alert("密码不能为空！");
					user_pwd.style.borderColor = "red";
				}
			}else{
				alert("用户名不能为空！");
				user_id.style.borderColor = "red";
			}
			
			user_id.value = "";
			user_pwd.value = "";
			
			
		})
		
		
		
	}
})
